package fudan.se.project.controller.conference.resource;


import fudan.se.project.service.advanced.conference.resource.ConferenceResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@Slf4j
@RestController
@RequestMapping("/conference")
public class ConferenceResourceController {

    private final ConferenceResourceService conferenceResourceService;

    @Autowired
    public ConferenceResourceController(ConferenceResourceService conferenceResourceService) {
        this.conferenceResourceService = conferenceResourceService;
    }

    @GetMapping("")
    public ResponseEntity<?> getConference(@RequestParam long id) {

        return conferenceResourceService.getConference(id);
    }

    @GetMapping("/paper/download")
    public ResponseEntity<?> downloadPaper(
            @RequestParam long id
    ) {
        return conferenceResourceService.downloadPaper(id);
    }

    @GetMapping("/topics")
    public ResponseEntity<?> getConferenceTopics(@RequestParam long id) {

        return conferenceResourceService.getConferenceTopics(id);
    }

    @GetMapping("/stage")
    public ResponseEntity<?> getConferenceStage(@RequestParam long id) {

        log.info("Get conference stage code of conference:" + id);
        return conferenceResourceService.getConferenceStage(id);
    }

    @GetMapping("/paper/post")
    public ResponseEntity<?> getPost(@RequestParam long id) {

        log.info("Get post for paper:" + id);
        return conferenceResourceService.getPost(id);
    }

    @GetMapping("/papers/unconfirmed")
    public ResponseEntity<?> getUnconfirmedPapers(@RequestParam long id,
                                                  @Validated @RequestParam @Min(0) @Max(1) int release) {
        log.info("Get unconfirmed papers in conference:" + id);
        return conferenceResourceService.getUnconfirmedPapers(id, release);
    }

    @GetMapping("/papers/unconfirmed/count")
    public ResponseEntity<?> getUnconfirmedCount(@RequestParam long id,
                                                  @Validated @RequestParam @Min(0) @Max(1) int release) {
        log.info("Get unconfirmed papers in conference:" + id);
        return conferenceResourceService.getUnconfirmedCount(id, release);
    }

    @GetMapping("/rebuttal/papers")
    public ResponseEntity<?> getRebuttedPapers(@RequestParam long id,
                                               @RequestParam boolean confirmed) {

        log.info("Get rebutted papers in conference:" + id);
        return conferenceResourceService.getRebuttedPapers(id, confirmed);
    }

    @GetMapping("/paper/rebuttal")
    public ResponseEntity<?> getRebuttal(@RequestParam long id) {

        log.info("Get rebuttal for paper:" + id);
        return conferenceResourceService.getRebuttal(id);
    }

}
